package com.wyg.epdata.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.*;

/**
 * @Author: WangYongGan
 * @Date: 2021/11/8 0:47
 * @Description: mp时间策略
 */
@Component
public class
MPConfig implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("createTime", new Date(), metaObject);
        this.setFieldValByName("updateTime", new Date(), metaObject);
    }


    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updateTime", new Date(), metaObject);
    }

    static Random random = new Random();

    //假设这是你的真随机的1-7函数
    public static int next7() {
        return random.nextInt(7) + 1;
    }

    static Map<Integer, Integer> map = new HashMap<>();

    static int mul = 1;

    public static int nextBigger() {
        int next = 0;
        for (int i = 0; i < mul; i++) {
            next += next7();
        }
        return next;
    }

    public static int next(int n) {
        mul = n / 7 + 1;
        int biggestIndex = 1;
        int max = nextBigger();
        for (int i = 2; i <= n; i++) {
            int next = nextBigger();
            while (next == max)
                next = nextBigger();
            if (next > max) {
                max = next;
                biggestIndex = i;
            }
        }
        return biggestIndex;
    }

    public static void main(String[] args) {
        for (int i = 0; i < 100; i++) {
            System.out.println(next(100));
        }
    }
}
